package com.mzx.javase.shuzu;

/**
 * @Description:数组拷贝，深拷贝和浅拷贝
 * @Date: 2022/1/3 17:51
 * @Author: MarKing
 */
public class Shuzukaobei {
    public static void main(String[] args) {
        //首先这里有一个数组
        int[] arr = {1, 4, 5, 6, 4, 2, 3, 4, 2, 1};
        //浅拷贝，只拷贝数组的内存地址，而不拷贝其中的内容
        int[] arr1 = arr;
        arr[1] = 9;
        for (int i : arr1) {
            System.out.print(i);
        }

        //深拷贝，拷贝其数值，和原先的数值一致
        //数组arrCopy 拷贝数组arr
        int[] arrCopy = new int[arr.length];
        for (int i = 0; i < arr.length - 1; i++) {
            arrCopy[i] = arr[i];
        }
        arrCopy[0] = 2;
        System.out.println();
        System.out.println("arr的值："+arr[0]);
        System.out.println("深拷贝数组arrCopy的值："+arrCopy[0]);

    }
}
